/**   
 * @Title: ShuangseqiuTermCommunicater.java 
 * @Package com.esun.rabbit2.communicaters 
 * @Description: (通讯接口 10006) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-6-27 下午06:43:30  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.hemaicenter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: FucaiTermCommunicater
 * @Description: (获取福彩3D当前期号)
 * @author: Kuroky Chengxt@500wan.com
 * @date: 2011-11-28 下午06:43:30
 * 
 */
public class FucaiTermCommunicater extends ServerCommunicater {
	private String msgServer; // 服务器信息
	private boolean isSucceed = false;

	// private String EXPECT = "expect";
	// private String ACTIVE = "active";
	// private String LEFTTIME = "lefttime";
	// private String LOTID = "lotid";
	// private static final String FUCAI_LOTID = "7";

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String msgServer) {
		this.msgServer = msgServer;
	}

	public boolean isGetDataSucceed() throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_FUCAI3D_TIMELEFT));
		list.add(mapItem(BussinessCode.PASER_CK, Config.NULLMARK));
		list.add(mapItem(Key.KEY_LOTID, Config.FUCAI3D));

		// 写入服务器返回信息
		super.getServerResponse(list, true);
		setMsgServer(super.getErrorMSG());
		if (super.getState() == 100) {
			isSucceed = true;
			updataFucai3dInfo();
		} else {
			isSucceed = false;
		}
		return isSucceed;
	}

	public void updataFucai3dInfo() {
		if (isSucceed) {
			for (int i = 0; i < super.getListResult().size(); i++) {
				if (Integer.parseInt((String) super.getListResult().get(i).get(Key.KEY_ACTIVE)) == 1) {
					Fucai3dInfo.getFucai3dInfo().setTermNum((String) super.getListResult().get(i).get(Key.KEY_EXPECT));
					Fucai3dInfo.getFucai3dInfo().setTimeLeft((String) super.getListResult().get(i).get(Key.KEY_LEFTTIME));
				}
			}
		}
	}

	/**
	 * @Title: mapItem
	 * @Description: (工具类,用于构建AraayList单条内容)
	 * @param @param name 参数名
	 * @param @param value 参数值
	 * @param @return map
	 * @return HashMap<String,String> 返回类型
	 * @throws
	 */
	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
